/**
 * @file filter
 * @author liaoxuezhi@baidu.com
 */
/* eslint fecs-indent: [0, "space", 2, 2] */

import * as React from 'react';
import {
  Component,
  PropTypes
} from 'react';
import {Renderer} from '../../renderer';
import * as cx from 'classnames';

@Renderer({
  name: 'crud-field-checkbox',
  desc: '...',
  test: /(?:^|\/)crud\/(.*?\/)field\/checkbox$/
})
export default class Checkbox extends Component {
  static propTypes = {
    className: PropTypes.string
  };

  render() {
    const {
      className,
      item,
      onCheck,
      disabled,
      stopClickPropagation
    } = this.props;

    return (
      <label
        className={cx('i-checks m-b-none', className)}
        onClick={stopClickPropagation ? e => e.stopPropagation() : null}
      >
        <input
          type="checkbox"
          checked={!!item.$checked}

          onChange={e => {
            onCheck && onCheck(e.currentTarget.checked, item);
          }}
          disabled={disabled}
        />
        <i />
      </label>
    );
  }
}
